package com.example.liang.basamovie.fragment.FindChildFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.liang.basamovie.R;
import com.example.liang.basamovie.adapter.MustNewAdapter;
import com.example.liang.basamovie.bean.FindBean;
import com.example.liang.basamovie.json.FindJson;
import com.example.liang.basamovie.utils.DataPath;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import java.util.List;

/**
 * 发现的　最新碎片
 */
public class MustNewFragment extends Fragment {
   RecyclerView recyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_find_mustnew_layout, null);
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //添加管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        //获取数据
        getData();
        //创建适配器


    }



    private void getData() {
        OkHttpUtils.get().url(DataPath.FIND_PATH).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                Toast.makeText(getContext(),"发现下载出错",Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onResponse(String response) {
                List<FindBean> list = FindJson.getList(response);
                MustNewAdapter adapter = new MustNewAdapter(list, getContext());
                recyclerView.setAdapter(adapter);

            }
        });

    }
}
